package hottargui.config;

import hottargui.framework.AttackStrategy;
import hottargui.framework.PlayerColor;
import hottargui.framework.Tile;

public class AlphaAttackStrategy implements AttackStrategy {

	@Override
	public void Attack(Tile fromTile, Tile toTile, int attackUnitsCount)
	{
		if(toTile.getOwnerColor() == PlayerColor.None)
		{
		  toTile.changePlayerColor(fromTile.getOwnerColor());
		  toTile.changeUnitCount(toTile.getUnitCount() + attackUnitsCount);
		  fromTile.changeUnitCount(fromTile.getUnitCount() - attackUnitsCount); //Moves the selected count to the tile
		}
		else
		{
			//This is when a Tile is attacked
			if(fromTile.getOwnerColor() != toTile.getOwnerColor())
			{
				int res = fromTile.getUnitCount() - toTile.getUnitCount();
				if(res > 0) //The attacker wins the battle, res is the remaining camels
				{
					toTile.changePlayerColor( fromTile.getOwnerColor());
					fromTile.changeUnitCount(fromTile.getUnitCount() - attackUnitsCount); //either the count are lost or the have to move to the attacked tile
					toTile.changeUnitCount(res); 		  
				}
				else //Defender is the winner of the battle
				{
					fromTile.changeUnitCount(fromTile.getUnitCount() - attackUnitsCount);
					toTile.changeUnitCount(-res);
				}
			}	
		}

	}
}
